package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.service.TypeTemplateService;
import com.dongdongshop.vo.TypeTemplateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("typeTemplate")
public class TypeTemplateController {

    @Autowired
    private TypeTemplateService typeTemplateService;

    @PostMapping("getTypeList")
    public Result getTypeList(@RequestBody TypeTemplateVO templateVO) {
        List<TypeTemplateVO> typeTemplateVOList = typeTemplateService.getTypeList(templateVO);
        return Result.OK().setData(typeTemplateVOList);
    }

    @PostMapping("addTypeTemplate")
    public Result addTypeTemplate(@RequestBody TypeTemplateVO template) {
        typeTemplateService.addTypeTemplate(template);
        return Result.OK();
    }

    @GetMapping("getTemplateById")
    public Result getTemplateById(@RequestParam Long id) {
        TypeTemplateVO typeTemplateVO = typeTemplateService.getTemplateById(id);
        return Result.OK().setData(typeTemplateVO);
    }

    @PostMapping("updateTypeTemplate")
    public Result updateTypeTemplate(@RequestBody TypeTemplateVO template){
        typeTemplateService.updateTypeTemplate(template);
        return Result.OK();
    }
    @DeleteMapping("deleteBatch")
    public Result deleteBatch(@RequestBody List<Long> ids){
        typeTemplateService.deleteBatch(ids);
        return Result.OK();
    }
    @GetMapping("getAllType")
    public Result getAllType() {
        List<TypeTemplateVO> voList = typeTemplateService.getAllType();
        return Result.OK().setData(voList);
    }

    @PostMapping("getTemplateByItemId")
    public Result getTemplateByItemId(@RequestParam Long itemId) {
        TypeTemplateVO typeTemplateVO= typeTemplateService.getTemplateByItemId(itemId);
        return Result.OK().setData(typeTemplateVO);
    }

}
